package com.tencent.qcloud.qiaoqiao.ui.adapter;

import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tencent.qcloud.qiaoqiao.R;
import com.tencent.qcloud.qiaoqiao.login.TCUserMgr;
import com.tencent.qcloud.qiaoqiao.ui.bean.CommentListBean;
import com.tencent.qcloud.qiaoqiao.ui.net.HttpRequest;
import com.tencent.qcloud.qiaoqiao.ui.net.HttpResultListener;
import com.tencent.qcloud.qiaoqiao.ui.tools.MyAppUtils;
import com.tencent.qcloud.qiaoqiao.ui.tools.utilCode.TimeUtils;
import com.tencent.qcloud.qiaoqiao.ui.tools.utilCode.ToastUtils;

import de.hdodenhof.circleimageview.CircleImageView;
import okhttp3.FormBody;
import okhttp3.RequestBody;

public class CommentListAdapter extends BaseQuickAdapter<CommentListBean.ListBean, BaseViewHolder> {

    public CommentListAdapter() {
        super(R.layout.adapter_comment_list);
    }

    @Override
    protected void convert(final BaseViewHolder viewHolder, final CommentListBean.ListBean item) {

        TextView comment_name_tx = viewHolder.getView(R.id.comment_name_tx);
        String name = item.getNickname();
        comment_name_tx.setText(MyAppUtils.getName(name));
        TextView comment_conntex_tx = viewHolder.getView(R.id.comment_conntext_tx);
        comment_conntex_tx.setText(item.getContent());

        TextView comment_time_tx = viewHolder.getView(R.id.comment_time_tx);
        comment_time_tx.setText(TimeUtils.generateTimeStr(TimeUtils.convertTimeToLong(item.getAdd_time())));

        TextView comment_tags_tx = viewHolder.getView(R.id.comment_tags_tx);
        viewHolder.addOnClickListener(R.id.comment_tags_tx);

        CircleImageView video_name_avatar = viewHolder.getView(R.id.video_name_avatar);
        String cover = item.getAvatar();
        if (TextUtils.isEmpty(cover)) {
            video_name_avatar.setImageResource(R.mipmap.home_head_icon);
        } else {
            RequestManager req = Glide.with(video_name_avatar.getContext());
            req.load(cover).placeholder(R.drawable.bg_ugc).into(video_name_avatar);
        }
        int action = item.getComment_state();
        Drawable drawable;
        if (action == 0) {
            drawable = ContextCompat.getDrawable(mContext, R.mipmap.comment_un_like_icon);
        } else {
            drawable = ContextCompat.getDrawable(mContext, R.mipmap.comment_ike_icon);
        }
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        comment_tags_tx.setCompoundDrawables(null, drawable, null, null);
        comment_tags_tx.setText(item.getCommend_count()+"");

    }

}